<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel="stylesheet" type="text/css" href="{{CDN}}/easyui/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="{{CDN}}/easyui/themes/icon.css">
		<script type="text/javascript" src="{{CDN}}/easyui/jquery.min.js"></script>
		<script type="text/javascript" src="{{CDN}}/easyui/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="{{CDN}}/easyui/locale/easyui-lang-zh_CN.js"></script>
		<script>

		$(function(){
					
			/*表格初始化*/
			$("#grid").datagrid({
				fit:true,
				fitColumns:true,
				collapsible:true, 
				striped:true,
				rownumbers:true, 
			    columns:[[    
					{field:'CK',checkbox:true},
					{field:'type',title:'类型',width:80,align:'left'}, 
			        {field:'name',title:'名称',width:200,align:'left'},    
			        {field:'url',title:'url',width:300,align:'left'},    
			        {field:'explain',title:'说明',width:700,align:'left'}
			    ]],
			    url:'/scheduler/invoke/getInterfaceList'
			});
			
			//查询按钮
			$("#search_btn").click(function(){
				$("#grid").datagrid('reload');
				
			});
			
			//调用按钮
			$("#exe_btn").click(function(){
				var rows = $('#grid').datagrid('getSelections');
				if(rows.length<1){
					$.messager.alert('提示','请勾选一条');
					return false;
				}
                id_str = ""
                for(var i=0;i<rows.length;i++){
                    id_str = id_str + rows[i].id+"^";
                }
				//window.open(rows[0].url)
                //现在考虑一下如果勾选多条怎么办，那就以“^”分割id
				$.post("/scheduler/invoke/exeInterface",{id:id_str},function(response){
					$.messager.alert('提示',JSON.stringify(response));
				})
				
			});
			
			//添加按钮
			$("#add_btn").click(function(){
				$("#add_dialog").dialog({ 
					title: '添加',    
					width: 1000,    
					height: 500,    
					closed: false,    
					cache: false,
			   		modal: true,
			   		buttons:[{
						text:'保存',
						iconCls:'icon-save',
						handler:function(){
							$.post("/scheduler/invoke/insertInterface",parent.getFormJson($('#add_form')),function(response){
								$("#add_dialog").dialog('close');
								$("#grid").datagrid('reload');
							})
						}
					}]
				});
			});
			
			
			//修改按钮
			$("#edit_btn").click(function(){
				var rows = $('#grid').datagrid('getSelections');
				if(rows.length<1){
					$.messager.alert('提示','请勾选一条');
					return false;
				}
				
				$("#edit_id").textbox("setValue", rows[0].id);
				$("#edit_type").textbox("setValue", rows[0].type);
				$("#edit_name").textbox("setValue", rows[0].name);
				$("#edit_url").textbox("setValue", rows[0].url);
				$("#edit_explain").textbox("setValue", rows[0].explain);
				$("#edit_dialog").dialog({ 
					title: '修改',    
					width: 1000,    
					height: 500,    
					closed: false,    
					cache: false,
			   		modal: true,
			   		buttons:[{
						text:'保存',
						iconCls:'icon-save',
						handler:function(){
							$.post("/scheduler/invoke/updateInterface",parent.getFormJson($('#edit_form')),function(response){
								$("#edit_dialog").dialog('close');
								$("#grid").datagrid('reload');
							})
						}
					}]
				});
			});	
		});
		</script>
	</head>

	<body class="easyui-layout">
		<!-- 主表格 -->
		<div region="center" border="false">
			<table id="grid" data-options="toolbar:'#toolbar'">
                <div id = 'toolbar'>
                    <a href="#" id="search_btn" class="easyui-linkbutton"	 
                        data-options="iconCls:'icon-search'"  >查询</a>
                    <a href="#" id='add_btn' class="easyui-linkbutton" 
                        data-options="iconCls:'icon-add'">添加</a>
                    <a href="#" id='edit_btn' class="easyui-linkbutton" 
                        data-options="iconCls:'icon-edit'">编辑</a>
                    <a href="#" id='exe_btn' class="easyui-linkbutton" 
                        data-options="iconCls:'icon-reload'">执行</a>
                </div>
            </table>
		</div>
		
		
		<!-- 一些隐藏的对话框 -->
		<!-- 新增子类页 -->
		<div style="display:none" id="add_dialog">
			<form id ="add_form" method="post" >
				<table width="100%">
					<tr>
						<td align="right" width="20%">接口类型:</td>
						<td width="20%"  align="left" >
							<input class="easyui-textbox"  id ="add_type" name="type" style="width:800px"  />
						</td>
					<tr>
					</tr>
						<td align="right" width="20%">接口名称:</td>
						<td width="20%"  align="left">
							<select class="easyui-textbox"  id="add_name" name="name"  style="width:800px">
						</td>
						<td width="20%" ></td>
					</tr>
					<tr>
						<td align="right" width="20%">url:</td>
						<td width="20%"  align="left">
							<select class="easyui-textbox"  id="add_url" name="url"  style="width:800px">
						</td>
						<td width="20%" ></td>
					</tr>
					<tr>
						<td align="right" width="20%">说明:</td>
						<td width="20%"  align="left">
							<select class="easyui-textbox"  id="add_explain" name="explain"  data-options="multiline:true" style="width:800px;height: 150px">
						</td>
						<td width="20%" ></td>
					</tr>
				</table> 
			</form>
		</div>
		
		<!-- 修改页 -->
		<div style="display:none" id="edit_dialog">
			<form id ="edit_form" method="post" >   
				<table width="100%">
					
					<tr style="display:none">
						<td align="right" width="20%">id:</td>
						<td width="20%"  align="left" >
							<input class="easyui-textbox"  id="edit_id"  name="id" style="width:200px"  />
						</td>
					<tr>
						<tr>
							<td align="right" width="20%">接口类型:</td>
							<td width="20%"  align="left" >
								<input class="easyui-textbox"  id ="edit_type" name="type" style="width:800px"  />
							</td>
						<tr>
						</tr>
							<td align="right" width="20%">接口名称:</td>
							<td width="20%"  align="left">
								<select class="easyui-textbox"  id="edit_name" name="name"  style="width:800px">
							</td>
							<td width="20%" ></td>
						</tr>
						<tr>
							<td align="right" width="20%">url:</td>
							<td width="20%"  align="left">
								<select class="easyui-textbox"  id="edit_url" name="url"  style="width:800px">
							</td>
							<td width="20%" ></td>
						</tr>
						<tr>
							<td align="right" width="20%">说明:</td>
							<td width="20%"  align="left">
								<select class="easyui-textbox"  id="edit_explain" name="explain" data-options="multiline:true" style="width:800px;height: 150px">
							</td>
							<td width="20%" ></td>
						</tr>
				</table> 
			</form>
		</div> 
		
	</body>
</html>
